using I2.Loc;
using UnityEngine;

public class QTotal : MonoBehaviour
{
	private UIPopupList curPop;

	private int selQ;

	private void Awake()
	{
		curPop = GetComponent<UIPopupList>();
	}

	private void Start()
	{
		UpdateParameter(true);
	}

	private void OnEnable()
	{
		if (QualityController.instance != null)
		{
			QualityController.onChangeQuality += UpdateParameter;
		}
		SwitchLanguage.onChangeLanguage += Localize;
		UpdateParameter();
		Localize();
	}

	private void OnDisable()
	{
		if (QualityController.instance != null)
		{
			QualityController.onChangeQuality -= UpdateParameter;
		}
		SwitchLanguage.onChangeLanguage -= Localize;
	}

	public void ChangeQuality()
	{
		if (QualityController.instance != null)
		{
			selQ = GetCurQuality();
			QualityController.instance.TotalQuality = selQ;
		}
	}

	private int GetCurQuality()
	{
		int i;
		for (i = 0; i < curPop.items.Count && !curPop.items[i].Equals(curPop.value); i++)
		{
		}
		return i;
	}

	private void UpdateParameter()
	{
		UpdateParameter(false);
	}

	private void UpdateParameter(bool force)
	{
		if (!(QualityController.instance != null))
		{
			return;
		}
		int totalQuality = QualityController.instance.TotalQuality;
		if (force || (totalQuality != GetCurQuality() && totalQuality < curPop.items.Count))
		{
			curPop.value = curPop.items[totalQuality];
			if (BCWDebug.isDebugBuild)
			{
				BCWDebug.Log("UpdateParameter total: " + curPop.value);
			}
		}
	}

	private void Localize()
	{
		selQ = GetCurQuality();
		curPop.items.Clear();
		curPop.items.Add(ScriptLocalization.Get("Lobby_Settings/Custom"));
		curPop.items.Add(ScriptLocalization.Get("Lobby_Settings/High"));
		curPop.items.Add(ScriptLocalization.Get("Lobby_Settings/Mid"));
		curPop.items.Add(ScriptLocalization.Get("Lobby_Settings/Low"));
		curPop.value = curPop.items[selQ];
	}
}
